﻿#region Usings

using PolyGameEngine.GamePieces;
using PolyGameEngine.GamePieces.Common;
using PolyGameEngine.Tools;

using FarseerPhysics.Dynamics;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

#endregion
namespace PolyMorph.CustomGamePieces
{
    public class ForceTile: AnimatedRectangleEffectGamePiece
    {
        Texture2D Spritesheet;
        float force;
        public ForceTile(PhysicsGame PhysicsGame, World World, Material Material, Texture2D SpriteSheet, int animationSpeed, Vector2 Position, Vector2 EffectOffset, float Rotation, float strenght, float DrawingDepth, int saveLineIndex, string GPID)
            : base(PhysicsGame, World, Material, Position,EffectOffset, Rotation,SpriteSheet ,animationSpeed , DrawingDepth, saveLineIndex, GPID)
            
        {
            Spritesheet = SpriteSheet;
            force = strenght;
        }

        public override void Effect()
        {
            float distanceFromTile = Vector2.Distance(bodyInEffect.Position,body.Position);
            float percentage = 1 - distanceFromTile / 1.3f;
            if (bodyInEffect!=null) 
            {
                if (percentage > 0.2f)
                    bodyInEffect.ApplyForce(MyMathClass.CalculateForceAtAngle(force ,rotation));
                else
                    bodyInEffect.ApplyForce(MyMathClass.CalculateForceAtAngle(force * 2f,rotation));
            }
        }


    }
}
